<template>
  <el-form ref="searchForm" :model="searchForm" label-width="120px">
    <el-row v-if="conditionCount > 0">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="店铺标题" prop="shopTitle" label-for="shopTitle">
          <el-input
            v-model="searchForm.shopTitle"
            element-id="shopTitle"
            placeholder="请输入店铺标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="商品类目名称" prop="categoryTitle" label-for="categoryTitle">
          <el-input
            v-model="searchForm.categoryTitle"
            element-id="categoryTitle"
            placeholder="请输入商品类目名称"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="商品标题" prop="title" label-for="title">
          <el-input
            v-model="searchForm.title"
            element-id="title"
            placeholder="请输入商品标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-button
          type="primary"
          style="margin-left: 10px;"
          :loading="loading.search"
          @click="handleSubmit"
        >搜索</el-button>
        <el-button @click="handleReset">重置</el-button>
        <a v-if="conditionCount > 3" style="margin-left: 10px;" @click="collapse = !collapse">
          <el-button type="text" v-if="!collapse">
            展开
            <svg-icon icon-class="ios-arrow-down" />
          </el-button>
          <el-button v-else type="text">
            收起
            <svg-icon icon-class="ios-arrow-up" />
          </el-button>
        </a>
      </el-col>
    </el-row>
    <el-row v-if="collapse">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="品牌名称" prop="brandTitle" label-for="brandTitle">
          <el-input
            v-model="searchForm.brandTitle"
            element-id="brandTitle"
            placeholder="请输入品牌名称"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="上架状态" prop="shelfStatus">
          <el-select
            v-model="searchForm.shelfStatus"
            placeholder="请选择上架状态"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.shelfStatusSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="销量">
          <el-row>
            <el-col :span="11">
              <el-form-item prop="saleCountMin">
                <el-input-number
                  v-model="searchForm.saleCountMin"
                  placeholder="请输入开始销量"
                  :controls="false"
                  style="width: 100%;"
                  @keyup.enter.native="handleSubmit"
                />
              </el-form-item>
            </el-col>
            <el-col :span="2" style="text-align: center">-</el-col>
            <el-col :span="11">
              <el-form-item prop="saleCountMax">
                <el-input-number
                  v-model="searchForm.saleCountMax"
                  placeholder="请输入结束销量"
                  :controls="false"
                  style="width: 100%;"
                  @keyup.enter.native="handleSubmit"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="8">
        <el-form-item label="点击数">
          <el-row>
            <el-col :span="11">
              <el-form-item prop="clickCountMin">
                <el-input-number
                  v-model="searchForm.clickCountMin"
                  placeholder="请输入开始点击数"
                  :controls="false"
                  style="width: 100%;"
                  @keyup.enter.native="handleSubmit"
                />
              </el-form-item>
            </el-col>
            <el-col :span="2" style="text-align: center">-</el-col>
            <el-col :span="11">
              <el-form-item prop="clickCountMax">
                <el-input-number
                  v-model="searchForm.clickCountMax"
                  placeholder="请输入结束点击数"
                  :controls="false"
                  style="width: 100%;"
                  @keyup.enter.native="handleSubmit"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
export default {
  name: 'GoodsInfoSearchQuick',
  data() {
    return {
      loading: {
        search: false,
      },
      conditionCount: 7,
      collapse: false,
      searchForm: {
        pageNo: 1,
        pageSize: 10,
        sortColumn: undefined,
        sortOrder: undefined,
        id: undefined,
        idMin: undefined,
        idMax: undefined,
        shopId: undefined,
        shopIdMin: undefined,
        shopIdMax: undefined,
        shopTitle: undefined,
        shopIsActive: undefined,
        shopIsActiveMin: undefined,
        shopIsActiveMax: undefined,
        categoryId: undefined,
        categoryIdMin: undefined,
        categoryIdMax: undefined,
        categoryTitle: undefined,
        categoryIsActive: undefined,
        categoryIsActiveMin: undefined,
        categoryIsActiveMax: undefined,
        title: undefined,
        picUrl: undefined,
        brandId: undefined,
        brandIdMin: undefined,
        brandIdMax: undefined,
        brandTitle: undefined,
        brandIsActive: undefined,
        brandIsActiveMin: undefined,
        brandIsActiveMax: undefined,
        intro: undefined,
        shelfStatus: undefined,
        shelfStatusMin: undefined,
        shelfStatusMax: undefined,
        saleCount: undefined,
        saleCountMin: undefined,
        saleCountMax: undefined,
        clickCount: undefined,
        clickCountMin: undefined,
        clickCountMax: undefined,
        version: undefined,
        versionMin: undefined,
        versionMax: undefined,
        createTime: undefined,
        createTimeMin: undefined,
        createTimeMax: undefined,
        updateTime: undefined,
        updateTimeMin: undefined,
        updateTimeMax: undefined,
        isActive: undefined,
        isActiveMin: undefined,
        isActiveMax: undefined,
      },
      dataDictCodes: ['YES_NO', 'SHELF_STATUS'],
      selects: {
        shopIsActiveSelect: [],
        categoryIsActiveSelect: [],
        brandIsActiveSelect: [],
        shelfStatusSelect: [],
        isActiveSelect: [],
      },
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'shopIsActive',
              dataProp: 'shopIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'categoryIsActive',
              dataProp: 'categoryIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'brandIsActive',
              dataProp: 'brandIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'SHELF_STATUS',
              formProp: 'shelfStatus',
              dataProp: 'shelfStatusSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'isActive',
              dataProp: 'isActiveSelect',
            })
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    resetForm(excludeProps) {
      for (let key in this.searchForm) {
        if (excludeProps && excludeProps.includes(key)) {
          continue
        }
        this.searchForm[key] = undefined
      }
    },
    handleSubmit() {
      this.$emit('quickSearch')
    },
    handleReset() {
      this.$emit('researchTable')
    },
  },
}
</script>
<style>
.ivu-quick-opt {
  text-align: right;
}
</style>